package com.sugar.real.estate.module.business.controller.app.userfollow;

import com.sugar.real.estate.framework.common.pojo.CommonResult;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.framework.idempotent.core.annotation.Idempotent;
import com.sugar.real.estate.framework.idempotent.core.keyresolver.impl.UserIdempotentKeyResolver;
import com.sugar.real.estate.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.real.estate.module.business.controller.app.userfollow.vo.AppUserFollowPageReqVO;
import com.sugar.real.estate.module.business.controller.app.userfollow.vo.AppUserFollowSaveReqVO;
import com.sugar.real.estate.module.business.service.userfollow.UserFollowService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.sugar.real.estate.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 用户关注")
@RestController
@RequestMapping("/biz/user-follow")
@Validated
public class AppUserFollowController {

    @Resource
    private UserFollowService userFollowService;

    @PostMapping("/create")
    @Operation(summary = "关注/取关")
    @Idempotent(timeout = 3, message = "您的手速太快啦！", keyResolver = UserIdempotentKeyResolver.class)
    public CommonResult<Boolean> createUserFollow(@Valid @RequestBody AppUserFollowSaveReqVO createReqVO) {
        userFollowService.createUserFollow(createReqVO, SecurityFrameworkUtils.getLoginUserId());
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户关注分页")
    public CommonResult<PageResult<?>> getUserFollowPage(@Valid AppUserFollowPageReqVO pageReqVO) {
        return success(userFollowService.appGetUserFollowPage(pageReqVO, SecurityFrameworkUtils.getLoginUserId()));
    }
}